package lab03.test06;

import lab02.test09.Student;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * Created by dell on 2017/12/29.
 */
public class Test {
    private BufferedReader bufferedReader = null;
    private BufferedWriter bufferedWriter = null;


    public static void main(String[] args) {
        Test wordStatistics = new Test();
        Map<String, Integer> word_map = null;
        try {
            word_map = wordStatistics.readFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        wordStatistics.sortAndWrite(word_map);
    }

    private void sortAndWrite(Map<String, Integer> word_map) {
    }

    public Map<String, Integer> readFile() throws IOException {
        //读文件
        StringBuffer stringBuffer = new StringBuffer();
        bufferedReader = new BufferedReader(new FileReader(new File("E:\\java.txt")));  //文件路径可自定义
        String line = "";
        while((line = bufferedReader.readLine()) != null)
            stringBuffer.append(line);
        bufferedReader.close();


        Pattern pattern = null;
        String[] words = pattern.split(stringBuffer.toString());
    Map<String, Integer> word_map = new HashMap<String, Integer>();
            for(String s : words){
        if(!word_map.containsKey(s)){
            word_map.put(s, 1);
        }
        else{
            int count = word_map.get(s);
            word_map.replace(s, count, count+1);
        }
    }
            return word_map;
}
}